﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[updateLogCt]  
 
 
AS
BEGIN
declare @startDate datetime 
declare @maxLogDate nvarchar
SELECT @maxLogDate =(select MAX(LogDate) FROM dbo.LogCt)
	select @startDate = convert(datetime,(select MAX(LogDate) FROM dbo.LogCt))
declare @endDate datetime 
	select @endDate =DATEADD(day,1, GETDATE()) 
 
	declare @dtTemp as datetime 
	select @dtTemp = @startDate   
	
		declare @logct as int 
	 DELETE [dbo].[LogCt] WHERE LogDate=@maxLogDate
	  
		
	while (@dtTemp < @endDate)
	begin 
	 
	
	 select @logct =(select COUNT(*) from [dbo].[Log] where CONVERT(varchar,CreateDT,23)=CONVERT(VARCHAR,@dtTemp,23))
	 
	 INSERT INTO [dbo].[LogCt]([LogDate],[LogCount],[CreateDT])VALUES(CONVERT(VARCHAR,@dtTemp,23),@logct,GETDATE())
select @dtTemp =DATEADD(day,1, @dtTemp)
	end 
 

	END
